package org.ithasu.filpilote.app.http;

import org.ithasu.filpilote.data.ControllerModel;
import org.ithasu.tools.Console;
import org.ithasu.tools.net.http.HTTPTools;
import org.ithasu.tools.net.http.ResourceHandler;

import com.sun.net.httpserver.HttpServer;

public class HttpServerApp {

	public static void main(String[] args) {
		// -- Model ----------------------------------------
		String filename = "/home/matthieu/wires.json";
		ControllerModel model = new ControllerModel();
		if (!model.getZoneModel().load(filename)) {
			Console.error("Unable to load : " + filename);
			return;
		}

		// -- Server ----------------------------------------
		HttpServer server = HTTPTools.create(8000);
		HTTPTools.registerContext(server, "/", new ResourceHandler(HttpServerApp.class, "static/index.html"));
		HTTPTools.registerContext(server, "/status", new StatusHandler(model));
		HTTPTools.registerExitContext(server, "/exit");

		server.start();
	}

}
